package com.photoeditor.demo.ui.widget.image.mixer;

import android.graphics.PorterDuff;

import com.common.base.ComponentContext;
import com.photoeditor.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by winn on 17/12/29.
 */

public class MixerMode {
    public static final int MODE_NORMAL = 1;
    public static final int MODE_OVERLAY = 2;
    public static final int MODE_MULTIPLY = 3;
    public static final int MODE_SCREEN = 4;
    public static final int MODE_DARKEN = 7;
    public static final int MODE_LIGHTEN = 9;

    private int mMode;

    public static List<MixerMode> loadAllMixerMode() {
        List<MixerMode> ret = new ArrayList<>();
        MixerMode mode = new MixerMode(MODE_NORMAL);
        ret.add(mode);
        mode = new MixerMode(MODE_OVERLAY);
        ret.add(mode);
        mode = new MixerMode(MODE_MULTIPLY);
        ret.add(mode);
        mode = new MixerMode(MODE_SCREEN);
        ret.add(mode);
        mode = new MixerMode(MODE_DARKEN);
        ret.add(mode);
        mode = new MixerMode(MODE_LIGHTEN);
        ret.add(mode);
        return ret;
    }

    public MixerMode(int mode) {
        mMode = mode;
    }

    public int getMode() {
        return mMode;
    }

    public PorterDuff.Mode getFilter() {
        return getFilterByMode(mMode);
    }

    public String getName() {
        return getName(mMode);
    }

    public int getDrawable() {
        return getDrawable(mMode);
    }

    public static PorterDuff.Mode getFilterByMode(int mode) {
        PorterDuff.Mode ret = null;
        switch (mode) {
            case MODE_NORMAL:
                ret = null;
                break;
            case MODE_OVERLAY:
                ret = PorterDuff.Mode.OVERLAY;
                break;
            case MODE_MULTIPLY:
                ret = PorterDuff.Mode.MULTIPLY;
                break;
            case MODE_SCREEN:
                ret = PorterDuff.Mode.SCREEN;
                break;
            case MODE_DARKEN:
                ret = PorterDuff.Mode.DARKEN;
                break;
            case MODE_LIGHTEN:
                ret = PorterDuff.Mode.LIGHTEN;
                break;
            default:
                ret = null;
        }
        return ret;
    }

    public static String getName(int mode) {
        String ret;
        int resId;
        switch (mode) {
            case MODE_NORMAL:
                resId = R.string.mixer_mode_normal;
                break;
            case MODE_OVERLAY:
                resId = R.string.mixer_mode_overlay;
                break;
            case MODE_MULTIPLY:
                resId = R.string.mixer_mode_multiply;
                break;
            case MODE_SCREEN:
                resId = R.string.mixer_mode_screen;
                break;
            case MODE_DARKEN:
                resId = R.string.mixer_mode_darken;
                break;
            case MODE_LIGHTEN:
                resId = R.string.mixer_mode_lighten;
                break;
            default:
                resId = R.string.mixer_mode_normal;
        }
        ret = ComponentContext.getContext().getString(resId);
        return ret;
    }

    public static int getDrawable(int mode) {
        int res;
        switch (mode) {
            case MODE_NORMAL:
                res = R.drawable.ic_mixer_normal;
                break;
            case MODE_OVERLAY:
                res = R.drawable.ic_mixer_overlay;
                break;
            case MODE_MULTIPLY:
                res = R.drawable.ic_mixer_mutiply;
                break;
            case MODE_SCREEN:
                res = R.drawable.ic_mixer_screen;
                break;
            case MODE_DARKEN:
                res = R.drawable.ic_mixer_darken;
                break;
            case MODE_LIGHTEN:
                res = R.drawable.ic_mixer_lighten;
                break;
            default:
                res = R.drawable.ic_mixer_normal;
        }
        return res;
    }
}
